package com.newly.api.sys.feign;

import com.newly.common.base.constants.ServerUriConstant;
import com.newly.common.base.entity.R;
import com.newly.common.base.entity.sys.menu.dto.MenuDto;
import com.newly.common.base.entity.valid.Insert;
import com.newly.common.base.entity.valid.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author gjm guan
 * @date 2021/9/10 10:44
 * @desc 菜单api
 */
@Api(tags = "菜单api")
@FeignClient(path = ServerUriConstant.NEWLY_SYS_MENU, name = ServerUriConstant.NEWLY_SYS_SERVICE_NAME)
public interface MenuClient {

    @ApiOperation("创建菜单")
    @PostMapping("/create")
    R create(@NotNull(message = "No request parameters")
             @Validated(Insert.class) @RequestBody MenuDto menuDto);

    @ApiOperation("删除菜单")
    @DeleteMapping("/deleteByIds")
    R deleteByIds(@NotEmpty(message = "menuIds can't be empty")
                  @RequestParam("menuIds") List<Integer> menuIds);

    @ApiOperation("刷新菜单缓存")
    @PostMapping("/refreshCache")
    R refreshCache();

    @ApiOperation("修改菜单")
    @PutMapping("/change")
    R change(@NotNull(message = "No request parameters")
             @Validated(Update.class) @RequestBody MenuDto menuDto);

    @ApiOperation("修改排序值")
    @PutMapping("/changeSortById")
    R changeSortById(@NotNull(message = "menuId can't be empty") @RequestParam("menuId") Integer menuId,
                     @NotNull(message = "sort can't be empty") @RequestParam("sort") Integer sort);

    @ApiOperation("导出模板")
    @GetMapping("/exportTemplate/xml")
    void exportTemplate(HttpServletResponse response);

    @ApiOperation("导出菜单(xml格式)")
    @GetMapping(value = "/export/xml")
    R exportXml(@RequestParam(value = "menuIds", required = false) List<Integer> menuIds,
                HttpServletResponse response);

    @ApiOperation("导入菜单(xml格式)")
    @PostMapping("/import/xml")
    R importXml(@NotNull(message = "menuXmlFile can't be empty")
                @RequestParam("menuXmlFile") MultipartFile multipartFile);

    @ApiOperation("查询菜单列表")
    @GetMapping("/list")
    R list(@NotNull(message = "offset can't be empty") @RequestParam("offset") Integer offset,
           @NotNull(message = "limit can't be empty") @RequestParam("limit") Integer limit,
           @RequestParam("abilityCode") Integer abilityCode,
           @RequestParam("typeCode") Integer typeCode,
           @RequestParam("createBy") Long createBy,
           @RequestParam("keyword") String keyword);

    @ApiOperation("查询当前用户菜单")
    @GetMapping("/queryInAuth")
    R queryInAuth();

    @ApiOperation("查询当前用户权限列表使用的菜单")
    @GetMapping("/queryPermListInAuth")
    R queryPermListInAuth();

    @ApiOperation("查询侧边栏菜单")
    @GetMapping("/queryLayoutInAuth")
    R queryLayoutInAuth();

    @ApiOperation("通过菜单id查询能力菜单")
    @GetMapping("/queryPageInnerInAuth")
    R queryPageInnerInAuth(@NotNull(message = "menuId can't be empty")
                           @RequestParam("menuId") Integer menuId);

    @ApiOperation("获取当前租户所有页面内菜单")
    @GetMapping("/listPageInnerMapInAuth")
    R listMenuAbilityMapInAuth();

    @ApiOperation("查询菜单类型")
    @GetMapping("/queryTypes")
    R queryTypes();

    @ApiOperation("查询菜单能力")
    @GetMapping("/queryAbility")
    R queryAbility();

    @ApiOperation("查询菜单创建人")
    @GetMapping("/queryCreateTenant")
    R queryCreateTenant();

    @ApiOperation("通过子菜单id查询父菜单(多)")
    @GetMapping("/queryParentByIds")
    R queryParentByIds(@NotEmpty(message = "childMenuIds can't be empty")
                       @RequestParam("childMenuIds") List<Integer> childMenuIds);

    @ApiOperation("通过子菜单id查询父菜单(单)")
    @GetMapping("/queryParentById")
    R queryParentById(@NotNull(message = "childMenuId can't be empty")
                      @RequestParam("childMenuId") Integer childMenuId);

    @ApiOperation("通过父菜单id查询菜单(多)")
    @GetMapping("/queryByParentIds")
    R queryByParentIds(@NotEmpty(message = "parentMenuIds can't be empty")
                       @RequestParam("parentMenuIds") List<Integer> parentMenuIds);

    @ApiOperation("通过父菜单id查询菜单(单)")
    @GetMapping("/queryByParentId")
    R queryByParentId(@NotNull(message = "parentMenuId can't be empty")
                      @RequestParam("parentMenuId") Integer parentMenuId);

    @ApiOperation("通过id查询菜单(多)")
    @GetMapping("/queryByIds")
    R queryByIds(@NotEmpty(message = "menuIds can't be empty")
                 @RequestParam("menuIds") List<Integer> menuIds);

    @ApiOperation("通过id查询菜单(单)")
    @GetMapping("/queryById")
    R queryById(@NotNull(message = "menuId can't be empty")
                @RequestParam("menuId") Integer menuId);

    @ApiOperation("通过类型获取菜单能力")
    @GetMapping("/queryAbilityByType")
    R queryAbilityByType(@NotNull(message = "typeCode can't be empty")
                         @RequestParam("typeCode") Integer typeCode);

    @ApiOperation("获取渲染规则")
    @GetMapping("/queryRenderRule")
    R queryRenderRule(@NotNull(message = "typeCode can't be empty")
                      @RequestParam("typeCode") Integer typeCode);

    @ApiOperation("获取当前类型支持的父菜单")
    @GetMapping("/querySupportParent")
    R querySupportParent(@NotNull(message = "typeCode can't be empty")
                         @RequestParam("typeCode") Integer typeCode);

    @ApiOperation("检查clientUri是否可用")
    @GetMapping("/checkClientUri")
    R checkClientUri(@NotBlank(message = "clientUri can't be empty")
                     @RequestParam("clientUri") String clientUri);
}
